﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartMD.Manager.Patient;
using SmartMD.DataModel.Entity;
using SmartMD.Manager.Common;
using SmartMD.Manager.Utils;
using SmartMD.DataAccess.Service;
using System.Collections.ObjectModel;
using Techstar.Dialog;
using System.Collections;
using Duoease.ContainerModel;

namespace SmartMD.Manager.Specimens
{
    /// <summary>
    /// Interaction logic for SpecStoreEditPad.xaml
    /// </summary>
    public partial class SpecStoreEditPad : UserControl
    {
        private PatientSearchResult patientSearchRslt = null;
        private Hashtable _cmbHashtable = new Hashtable();
        public ContainerModelView _CM = null;
        public string Positon = "";
        public string ContainerID = "";

        public SpecStoreEditPad()
        {
            InitializeComponent();
        }

        private SpecInfo _dataSource;
        public SpecInfo DataSource
        {
            get
            {
                return _dataSource;
            }
            set
            {
                _dataSource = value;
                this.DataContext = _dataSource;
            }
        }

        private void NewPatient_Click(object sender, RoutedEventArgs e)
        {
            
        }

        /**
         *  功能：清空编辑区域
         * 
         * */
        public void Clear()
        {
            this.txtContainer.Text = "";
            this.txtCollector.Text = "";
            this.txtFollowUpDate.Text = "";
            this.txtPatient.Text = "";
        //    this.txtSpecType.Text = "";
            this.txtSubject.Text = "";
            this.txtSubject.Text = "";
            this.txtfreezeThrawTimes.Text = "";
            this.txtSpecSpecification.Text = "";
            this.txtSpecNum.Text = "";
        }
        
       
        private void cmbSpecState_Initialized(object sender, EventArgs e)
        {
            _cmbHashtable.Add("标本状态", sender);
            ComboxUtil.InitializeComboxByDict(sender, "标本状态");   
        }
        private void txtSpecSpecification_Initialized(object sender, EventArgs e)
        {
            _cmbHashtable.Add("标本规格", sender);
            ComboxUtil.InitializeComboxByDict(sender, "标本规格");   
        }
        public void InitAllComboxValue()
        {
            string key;
            object sender;
            foreach (DictionaryEntry de in _cmbHashtable)
            {
                key = de.Key.ToString();
                sender = de.Value as object;
                ComboxUtil.InitializeComboxByDict(sender, key);   
            }      
        }
        /**
         * 功能：位置选择
         * 
         * */
        public SiteSelectDialog SiteSelectDlg = null;
        private void BtnSearchSite_Click(object sender, RoutedEventArgs e)
        {
            int specNum = 0;
            try
            {
                specNum = int.Parse(this.txtSpecNum.Text == "" ? "0" : this.txtSpecNum.Text);
            }
            catch (Exception ex)
            {
                TaskDialogEx.Warning("提示", "请检输入标本数！");
                return;
            }
            if (specNum < 1)
            {
                TaskDialogEx.Warning("提示", "请检输入标本数！");
            }
            else
            {
                SiteSelectDlg = new SiteSelectDialog(this, specNum, DataSource.Id);
                SiteSelectDlg.ShowDialog();
            }
        }

        private void BtnSearchPatient_Click(object sender, RoutedEventArgs e)
        {
        
            patientSearchRslt = new PatientSearchResult();
            patientSearchRslt.Owner = this;
          /*  ObservableCollection<PatientInfo> patientInfoList = DataServiceManager.PatientInfoService.loadAllPatientInfos();
            for (int i = 0; i < patientInfoList.Count; i++)
            {
                patientSearchRslt.PatientInfoList.Add(patientInfoList[i]);
            }*/

            patientSearchRslt.ShowDialog();
        }
        /**
         * 功能：标本数改变事件
         * 
         * */
        private void txtSpecNum_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.txtContainer.Text = "未存入";
        }

        /**
         * 功能 ： 验证用户输入
         * 
         * */
        public bool Verify()
        {
            if (DataSource == null)
                return true;
  
            if (DataSource.FollowUpDate == null)
            {
                TaskDialogEx.Warning("请选择随访时间!");
                return false;
            }
            if (string.IsNullOrEmpty(DataSource.SpecNum.ToString()))
            {
                TaskDialogEx.Warning("请输入标本数!");
                return false;
            }
            if (string.IsNullOrEmpty(DataSource.PatientId))
            {
                TaskDialogEx.Warning("请选择标本关联的患者!");
                return false;
            }
            if (this.txtContainer.Text == "未存入")
            {
                TaskDialogEx.Warning("请关联标本位置!");
                return false;
            }
            return true;
        }

       /* private void txtSpecType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (txtSpecType.SelectedItem == null)
                return;
            string speccode = (txtSpecType.SelectedItem as ComboBoxValueItem).Value.ToString();
            this.DataSource.SpecType = speccode;
        }*/

        private void btnSearchFollowupInfo_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
